package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TrPson;
import com.ruoyi.system.service.ITrPsonService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 人脉管理Controller
 * 
 * @author ruoyi
 * @date 2024-05-26
 */
@RestController
@RequestMapping("/system/pson")
public class TrPsonController extends BaseController
{
    @Autowired
    private ITrPsonService trPsonService;


    /**
     * 获取所有的人员
     */
    @GetMapping("/getAllPson")
    public R getAllPson(TrPson trPson)
    {
        List<TrPson> list = trPsonService.selectTrPsonList(trPson);
        return R.ok(list);
    }

    /**
     * 查询人脉管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:pson:list')")
    @GetMapping("/list")
    public TableDataInfo list(TrPson trPson)
    {
        startPage();
        List<TrPson> list = trPsonService.selectTrPsonList(trPson);
        return getDataTable(list);
    }

    /**
     * 导出人脉管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:pson:export')")
    @Log(title = "人脉管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrPson trPson)
    {
        List<TrPson> list = trPsonService.selectTrPsonList(trPson);
        ExcelUtil<TrPson> util = new ExcelUtil<TrPson>(TrPson.class);
        util.exportExcel(response, list, "人脉管理数据");
    }

    /**
     * 获取人脉管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:pson:query')")
    @GetMapping(value = "/{psonId}")
    public AjaxResult getInfo(@PathVariable("psonId") Long psonId)
    {
        return success(trPsonService.selectTrPsonByPsonId(psonId));
    }

    /**
     * 新增人脉管理
     */
    @PreAuthorize("@ss.hasPermi('system:pson:add')")
    @Log(title = "人脉管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrPson trPson)
    {
        return toAjax(trPsonService.insertTrPson(trPson));
    }

    /**
     * 修改人脉管理
     */
    @PreAuthorize("@ss.hasPermi('system:pson:edit')")
    @Log(title = "人脉管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrPson trPson)
    {
        return toAjax(trPsonService.updateTrPson(trPson));
    }

    /**
     * 删除人脉管理
     */
    @PreAuthorize("@ss.hasPermi('system:pson:remove')")
    @Log(title = "人脉管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{psonIds}")
    public AjaxResult remove(@PathVariable Long[] psonIds)
    {
        return toAjax(trPsonService.deleteTrPsonByPsonIds(psonIds));
    }
}
